package com.hj.system.base.utils;

import com.hj.system.base.BaseDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Data
public class PageUtils implements Serializable {
    private static final Long serialVersionUID = 1L;
    private long total;
    private List<?> rows;

    public PageUtils(List<?> list, long total) {
        this.rows = list;
        this.total = total;
    }

    public static PageUtils getPageUtils(BaseDao baseService, Map<String, Object> map) {
        List list1 = baseService.list(map);
        PageHelper.clearPage();
        PageHelper.offsetPage(Integer.valueOf(map.get("offset").toString()), Integer.valueOf(map.get("limit").toString()));
        List list = baseService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        return new PageUtils(pageInfo.getList(), pageInfo.getTotal());
    }
}
